package com.xiaoyu.lanling.feature.moment.controller.notice

import `in`.srain.cube.views.list.CubeRecyclerViewSimpleAdapter
import `in`.srain.cube.views.list.PagedListDataModelWithRequestTag
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.xiaoyu.base.event.AppEventBus
import com.xiaoyu.base.event.SimpleEventHandler
import com.xiaoyu.base.view.list.BaseListViewController
import com.xiaoyu.lanling.event.moment.notice.LikeNoticeListEvent
import com.xiaoyu.lanling.feature.moment.model.notice.LikeNoticeItem
import com.xiaoyu.lanling.feature.moment.viewholder.notice.LikeNoticeImageItemViewHolder
import com.xiaoyu.lanling.feature.moment.viewholder.notice.LikeNoticeTextItemViewHolder
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class LikeNoticeListController(context: Context, listData: PagedListDataModelWithRequestTag<LikeNoticeItem, Any>, adapter: CubeRecyclerViewSimpleAdapter<LikeNoticeItem>, swipeRefreshLayout: SwipeRefreshLayout, recyclerView: RecyclerView) : BaseListViewController<LikeNoticeItem, Any>(context, listData, adapter, swipeRefreshLayout, recyclerView) {

    companion object {

        fun create(context: Context, listData: PagedListDataModelWithRequestTag<LikeNoticeItem, Any>, swipeRefreshLayout: SwipeRefreshLayout, recyclerView: RecyclerView): LikeNoticeListController {
            val adapter = CubeRecyclerViewSimpleAdapter<LikeNoticeItem>()
            adapter.setViewHolderClass(LikeNoticeItem.TYPE_IMAGE, null, LikeNoticeImageItemViewHolder::class.java, 20)
            adapter.setViewHolderClass(LikeNoticeItem.TYPE_TEXT, null, LikeNoticeTextItemViewHolder::class.java, 20)

            val controller = LikeNoticeListController(context, listData, adapter, swipeRefreshLayout, recyclerView)

            AppEventBus.bindContainerAndHandler(context, object : SimpleEventHandler() {

                @Subscribe(threadMode = ThreadMode.MAIN)
                fun onEvent(event: LikeNoticeListEvent) {
                    controller.onListEvent(event)
                }
            })

            return controller
        }
    }
}